Common problems in grid. Troubleshooting
XML loading
There are several common problems with XML loading:
a) Incorrect XML
In case of any problem with an incoming XML stream the grid will show "Incorrect XML" message.
The reasons of this problem are:
- Incorrect XML structure - it may be caused by incorrectly formed XML tags, or by using some special content (& < > chars) inside the tag values. The simplest way to detect the reason of an XML error is open the url used for XML loading in a separate browser window. It will show the error details and exact position of the problematic code;
- (IE specific) Usage of incorrect content type - if you are using dynamic XML source (generate it by the script), you need to send the data with Content-type:text/xml;
- (FF specific) In case of FF the problem may occur because of any whitespace before <?xml declaraton (the declaration must be the first text in the output).
If you are using a dynamic XML source, pay attention to the fact that the output during a stand alone test may not be equal to the output during the usage of the same feed with the component. You can try to use the debug version of dhtmlxcommon to check which urls are used and which xml output was sent during the data loading.
(The debug version of dhtmlxcommon can be taken from here).
b) Asynchronous way of XML loading
By default XML loading is asynchronous, which means that the following command will be executed after loadXML in the moment when the data has not really loaded yet. You need to catch the moment when the data will be loaded before executing any commands against it:
grid.loadXML(url,function(){
//any code
});
or
grid.attachEvent("onXLE",function(){
//any code
})
c) Data encoding
The component is encoding-agnostic and can work with any encoding supported by the browser (which means with any common encoding), but to process the data correctly the following steps must be executed:
- an HTML page must be loaded in the desired encoding;
- an XML must have correct encoding defined:
<?xml version="1.0" encoding="iso-8859-1" >
Pay your attention to the fact that in loadXMLString mode, IE can load only UTF8 based XML data.
Events
a) The names of the events are case sensitive. The component will not throw an error if you are using an incorrect event name.
b) Many events are blockable (the details can be checked in the related document), which means returning "false" from it will block the default reaction. Pay attention to the fact that the function which returns nothing is equal to returning "false". This means the following: if a custom event handler does not end with
return true;
it will block the default event processing. (It is always a good habit to finish the custom event handlers with "return true;").
c) You can attach multiple custom functions to one and the same event. When you attaching a new one, the previous function is not detached. Both the new and the old one will be executed when the event is fired. (To detach an event grid.detachEvent can be used).
Split mode
a) In the split mode the grid is slower than in the normal one. This can't be fixed.
b) The only one split per grid is possible.
c) After applying of the split mode to the grid, it is not possible to recreate the grid structure (reload the grid with a different structure). Such grid can be only destructed.
d) The splitAt must be executed only after defining of structure, but before data loading.
In case of initialization from JavaScript:
grid.setHeader(....
...
grid.init()
grid.splitAt(2)
grid.load(...
In case of loading configuration from XML:
<rows>
<head>
<column....
....
<afterInit>
<call command="splitAt"><param>2</param></call>
</afterInit>
In case of loading from HTML
<table class="dhtmlxGrid" split="2"....
Used js files
a) The "method is undefined" error - the functionality of the component is split between a few files. So the most common reason of the problem is that some necessary file is not included (you can check API reference, it contains the names of the files in which the related functionality is stored).
b) The "dhtmlxExcell undefined" or a similar error - the order of files loading is the problem here. The correct order is the following:
dhtmlxcommon.js
dhtmlxgrid.js
dhtmlxgridcell.js
any other js file
c) Be sure that file names are written in exactly the same case as in the file system (lowercase). While it may not be important for Window based software, it is crucial for MacOs|Linux based one.
Problems with adding|sorting|deleting
a) Be sure that each row has a unique ID. If IDs are not unique, the grid can show a lot of weird errors. If you are adding a row, the most simple way to get a unique ID - grid.uid()
b) Mixing a row ID and a row Index - each row in the grid can be addressed by an ID or an index. IDs are consistent, indexes can be changed by sorting|adding|deleting. Most functions of the grid use rowID but some of them can accept rowIndexes - be sure to use the necessary ones (the API reference contains the description of all incoming parameters).
c) If you are loading data from an external file, you need to wait while the data is loaded (asynchronous loading is described above).
© DHTMLX, 2008